package com.example.page;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import com.example.page.MyPageFactory;

public class LoginPage extends AnyPage{

    @FindBy(id = "username")
    public WebElement userNameField;

    @FindBy(name = "password")
    public WebElement passwordField;

    @FindBy(name = "submit")
    public WebElement loginButton;

    @FindBy(id ="loginform")
    public WebElement loginForm;

    public boolean isOnThisPage() {
         return loginForm.isDisplayed();
    }

     public InternalPage loginAsValid(String username, String password) {
         userNameField.sendKeys(username);
         passwordField.sendKeys(password);
         loginButton.click();
         return MyPageFactory.getPage(driverFirefox, InternalPage.class);
    }
     public LoginPage loginAsInvalid(String username, String password) {
         userNameField.sendKeys(username);
         passwordField.sendKeys(password);
         loginButton.click();
         return MyPageFactory.getPage(driverFirefox, LoginPage.class);
    }

    @Override
    void tryToOpen(){
        MyPageFactory.getPage(driverFirefox,InternalPage.class).logOut();
    }
}
